package model;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;

import enums.MaintainRecordsType;
import model.base.BaseMaintainRecords;

@SuppressWarnings("serial")
public class MaintainRecords extends BaseMaintainRecords<MaintainRecords> {
    public static final MaintainRecords dao = new MaintainRecords().dao();
    
    public Record findRecentRecords(int type , Long stationId) {
		return Db.findFirst(" SELECT tmr.id,tmr.createTime,tmr.recorder,tmr.type,tmr.recordsName,tmr.deadline,tmr.result,ts.name FROM t_maintain_records tmr LEFT JOIN t_servicer ts ON ts.id = tmr.servicerId WHERE tmr.stationId = ? AND tmr.type = ? ORDER BY  tmr.createTime DESC LIMIT 1 " , stationId , type);
	}
    
    public static List<Map<String, Object>> listByType(String type) {
		List<Map<String, Object>> list = new ArrayList<>();
		List<Map<String, Object>> datas = MaintainRecordsType.toList();
		for (Map<String, Object> map : datas) {
			int value = (int) map.get("value") ;
			if ( value != 3 && value != 5 ) { 
				list.add(map);
			}
		}
		return list;
	}
}
